<?php

namespace app\worker\middleware;

class Cors
{
    public function handle($request, \Closure $next)
    {
        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Methods:GET, POST, PUT, OPTIONS, DELETE");
        header("Access-Control-Allow-Headers: *");
        //header('Access-Control-Allow-Credentials: true');

        // 如果请求是OPTIONS方法，则直接返回空响应
        if ($request->method() === 'OPTIONS') {
            return response('');
        }

        return $next($request);
    }

}
